<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
</head>
<body>
<jsp:include page="head.jsp"></jsp:include>

<div class="body">
    <div>
        <ul class="list fl" id="list">
        </ul>
    </div>
    <div class="clear"></div>
    <div>
        <div class="easyui-panel">
            <div id="page" class="easyui-pagination"></div>
        </div>
    </div>
</div>


</body>
<script>
    var initPageSize = 15;
    var initPageNumber = 1;

    $(function(){
        list(initPageNumber, initPageSize);
    });

    $('#page').pagination({
        pageSize: initPageSize,    /* 初始的页大小 */
        pageNumber: initPageNumber,  /* 初始的页码 */
        total: ${leaseCount},    /* 同步方法，获取表的记录数 */
        layout:['first','prev','links','next','last'],
        onSelectPage: function(pageNumber, pageSize) {
            list(pageNumber, pageSize);
        }
    });

    function list(pageNumber, pageSize) {
        console.log("页码：" + pageNumber + '，条数：' + pageSize);

        $.ajax({
            url: "/lease/public/findByPage",
            type: "POST",
            dataType: "json",
            data: {
                pageNumber: pageNumber,
                pageSize: pageSize
            },
            success: function(result) {
                console.log(result);

                if(result.success) {
                    let html = '';
                    $.each(result.data, function(index, data) {
                        html = html + '<li><a href="/lease/public/detail/' + data.id + '">' + data.title + '/' + data.house.floor + '层/' + data.price + '元（月）</a></li>';
                    });

                    $("#list").html(html);
                } else {
                    top.$.messager.show({
                        title: 'Error',
                        msg: '网络错误'
                    });
                }

            }
        });
    }


</script>
</html>